/***************************************************************************
 *   Copyright (C) 2008 - 2009 by Pavel Andreev                            *
 *   Mail: apavelm on gmail point com (apavelm@gmail.com)                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include <QApplication>
#include <QtGui>

#include <QTranslator>
#include <QLocale>
#include <QLibraryInfo>

#include "mainwindowimpl.h"


int main(int argc, char ** argv)
{
	/** @todo option add "splash screen" */
	bool bSplash = true;
	/** @todo option add "tray icon" */
	// bool bTrayIcon = true;
	/////////////////////////////////////////////
	
	QApplication app( argc, argv );
	
	QPixmap pixmapSplash(":/images/splash.png");
	QSplashScreen splashScreen(pixmapSplash);
	Qt::Alignment alignBC = Qt::AlignBottom | Qt::AlignHCenter;
	
	if (bSplash)
	{
		splashScreen.show();
		
		// Repeat this block for each action
		splashScreen.showMessage(QObject::tr("Starting..."), alignBC, Qt::black);
		app.processEvents();
	}
	
	// Localize Qt framework
	QTranslator qtTranslator(&app);
	QString slocaleName = QLocale::system().name();
	if (bSplash) 
			splashScreen.showMessage(QObject::tr("Loading translations (localizing Qt)..."), alignBC, Qt::black);
	qtTranslator.load("qt_" + slocaleName, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
	app.installTranslator(&qtTranslator);
	app.processEvents();
	
	if (bSplash) 
		splashScreen.showMessage(QObject::tr("Loading translations (application)..."), alignBC, Qt::black);
	QTranslator appTranslator(&app);
	appTranslator.load(slocaleName, ":/lang/", QString(), ".qm");
	app.installTranslator(&appTranslator);
	app.processEvents();
	
//	if (bTrayIcon)
//	{
//		if (bSplash) 
//			splashScreen.showMessage(QObject::tr("Creating tray icon..."), alignBC, Qt::black);
//		app.processEvents();
//		if (!QSystemTrayIcon::isSystemTrayAvailable()) 
//			{
//				QMessageBox::critical(0, QObject::tr("Systray"), QObject::tr("I couldn't detect any system tray on this system."));
//				fprintf(stderr,"System tray wasn't found!\r\n");
//				return 1;
//			}
//	}
	
	MainWindowImpl win;
	win.show(); 
	app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );

	splashScreen.finish(&win);
	
	return app.exec();
}
